<?php
namespace app\service;
use think\facade\Db;

class communityService{
    const STATUS_SYNC = 'PENDING_SYNC';//待同步
    const STATUS_PAND = 'PENDING_ONLINE';//待审核
    const STATUS_ONLINE = 'ONLINE';//上线
    const STATUS_MAINTAIN = 'MAINTAIN';//维护中
    const SATTUS_OFFLINE = 'OFFLINE';//下线

    public function getZftInfo($id){
        $community=Db::table("community")->where("id",$id)->find();
        return Db::name('property_zftset')->where('property_id',$community["property_id"])->find();
    }
    //查询token
    public function communityinfoToken($community_id){
        $property_id = Db::name('community')->where('community_id',$community_id)->value('property_id');
        return Db::name('property')->where('id',$property_id)->value('accredit');
    }
    
    //查询小区数据
    public function communityList($where){
        return Db::name('community')->where($where)->order('id','desc')->select();
    }
    //查询小区数据条数
    public function communityNumber($where){
        return Db::name('community')->where($where)->select();
    }
    //查询指定ID物业名称
    public function propertyIdName($id){
        return Db::name('property')->where('id',$id)->value('name');
    }
    //查询物业信息
    public function propertyList($where){
        return Db::name('property')->where($where)->select();
    }
    //判断小区是否重复
    public function communityName($name){
        return Db::name('community')->where('community_name',$name)->find();
    }
    //添加小区信息
    public function communityAdd($data){
        return Db::name('community')->insert($data);
    }
    //查询小区信息
    public function communityIdInfo($id){
        return Db::name('community')->where('id',$id)->find();
    }
    //查询token
    public function propertyToken($property){
        return Db::name('property')->where('id',$property)->find();
    }
    public function communityIdEdit($data){
        return Db::name('community')->update($data);
    }
    //通过Communityid寻找Community
    public function fetchCommunityByCommunityId($community_id) {
        return Db::name('community')->where('community_id', $community_id)->find();
    }
    //修改
    public function communityEdit($id, $data) {
        return Db::name('community')->where('community_id', $id)->update($data);
    }
    //------------------------------费用类型------------------------------------------
    //查询费用类型数据
    public function costtypeList(){
        return Db::name('costtype')->order('id asc')->select();
    }
    //查询费用类型条数
    public function costtypeNumber(){
        return Db::name('costtype')->select();
    }
    //查询费用类型是否已添加
    public function costtypeName($type){
        return Db::name('costtype')->where('type',$type)->find();
    }
    public function costListWhere($where,$community_id){
        return Db::name('costtype')->where("community_id","in",$community_id)->where($where)->order('id asc')->select();
    }
    public function costNumberWhere($where,$community_id){
        return Db::name('costtype')->where("community_id","in",$community_id)->where($where)->count();
    }
    public function costName($type,$community_id){
        return Db::name('costtype')->where('type',$type)->where('community_id',$community_id)->find();
    }
    //添加费用类型
    public function costtypeAdd($data){
        return Db::name('costtype')->insert($data);
    }
    //查询指定ID费用类型信息
    public function costtypeId($id){
        return Db::name('costtype')->where('id',$id)->find();
    }
    //修改指定ID费用类型信息
    public function costtypeUpdate($data){
		return Db::name('costtype')->update($data);
    }
    //------------------------------费用类型------------------------------------------
    //配置打印机
    public function communityprinting($data){
        return Db::name('community')->update($data);
    }
}